package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.kaisengit.enity.User;
import com.kaishengit.util.DBHelp;
import com.kaishengit.util.RowMapper;

public class UserDao {
	
	private DBHelp <User> db = new DBHelp<User>();

	public User findByNamePwd(String name, String pwd) {
		String sql = "select id ,username,userpwd,role from t_user where username = ? and userpwd = ?";
		
		return db.executeQueryForObject( sql, new UserRowMapper(), name,pwd);
	}
	
	public class UserRowMapper implements RowMapper<User>{
		
		public User mapperRow (ResultSet rs) throws SQLException{
			
			User user = new User();
			user.setId(rs.getString("id"));
			user.setUsername(rs.getString("username"));
			user.setRole(rs.getString("role"));
			user.setUserpwd(rs.getString("userpwd"));
			return user;
			
			
		}
	}

	

}
